package com.itheima.service.impl;

import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import com.itheima.utils.MD5Utils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
    @Override
    public Member findByTelephone(String telephone) {
        Member member = memberDao.findByTelephone(telephone);
        return member;
    }

    @Override
    public void add(Member member) {
        //如果有密码就证明是表单注册
        if (member.getPassword()!=null) {
            member.setPassword(MD5Utils.md5(member.getPassword()));
        }
        memberDao.add(member);
    }
/*报表制作*/
    @Override
    public List<Integer> findMemberCountByMonths(List<String> months) {
              List<Integer> memberCount =new ArrayList<>();
        for (String month : months) {
            String date = month + ".31";//2018.05.31
            Integer count = memberDao.findMemberCountBeforeDate(date);
            memberCount.add(count);
        }
        return memberCount;
    }
    //通过微信登录的唯一标识查询用户
    @Override
    public Member findMemberByidCard(String idCard) {
    Member member= memberDao.findMemberByidCard(idCard);
    return member;

    }
}
